local xiansi = fk.CreateSkill{
    name = "SP_heg__xiansi",
    attached_skill_name = "SP_heg__xiansi_viewas&",
    derived_piles = "heg__liufeng_ni",
}

Fk:loadTranslationTable{
    ["SP_heg__xiansi"] = "陷嗣",
    [":SP_heg__xiansi"] = "准备阶段，你可以将一张手牌当【决斗】对一名其他角色使用，若此牌造成伤害，你选择其的一张牌置于你的武将牌上，称为“逆”，否则你摸一张牌。当其他角色需要对你使用【杀】时，其可以移去两张颜色相同的“逆”，视为对你使用【杀】。",
    ["#SP_heg__xiansi-choose"] = "陷嗣：选择一名其他角色，视为对其使用【决斗】",
    ["#SP_heg_xiansi_vs-use"] = "陷嗣：选择你的一张手牌当作【决斗】对一名其他角色使用",
    ["heg__liufeng_ni"] = "逆",

    ["$SP_heg__xiansi1"] = "父亲素来信我，为何会有今日之祸？",
    ["$SP_heg__xiansi2"] = "关二叔心中，何曾有过我这侄儿！？",
}

xiansi:addEffect(fk.EventPhaseStart,{
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(xiansi.name) and player.phase == Player.Start and not player:prohibitUse(Fk:cloneCard("duel"))
    and target == player and not player:isKongcheng()
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player.dead or #player:getHandlyIds() == 0 then return end
    room:askToUseVirtualCard(player, {
          name = "duel",
          skill_name = xiansi.name,
          prompt = "#SP_heg_xiansi_vs-use",
          card_filter = {
          n = 1,
          cards = player:getHandlyIds()},
          cancelable = true,
    })
  end,
})

xiansi:addEffect(fk.Damage,{
    mute = true,
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
        return target == player and not player.dead and player.room.logic:damageByCardEffect(true) and
            data.card and table.contains(data.card.skillNames, xiansi.name) and not data.to:isNude()
      end,
      on_cost = Util.TrueFunc,
      on_use = function(self, event, target, player, data)
        local room = player.room
        if data.to.dead or player.dead then return end
        local card = room:askToChooseCard(player,{
            target = data.to,
            flag = "he",
            skill_name = xiansi.name,
        })
        player:addToPile("heg__liufeng_ni", card, true, xiansi.name)
    end,
})

xiansi:addEffect(fk.CardUseFinished,{
    mute = true,
    is_delay_effect = true,
    can_trigger = function(self, event, target, player, data)
          return target == player and not player.dead and data.card and table.contains(data.card.skillNames, xiansi.name)
          and not data.damageDealt
      end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
        player:drawCards(1, xiansi.name)
    end,
})

return xiansi